package com.zzyl.nursing.controller;

import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingProject;
import com.zzyl.nursing.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目管理控制器
 *
 * 提供护理项目的增删改查、导出等功能接口
 *
 * @author ruoyi
 * @date 2025-10-27
 */
@Api(tags = "护理项目管理", description = "提供护理项目信息的查询、新增、修改、删除和导出功能")
@RestController
@RequestMapping("/nursing/project")
public class NursingProjectController extends BaseController {

    @Autowired
    private INursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     */
    @ApiOperation(value = "获取护理项目分页列表", notes = "根据条件分页查询护理项目信息，支持按名称、状态等筛选")
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/list")
    public TableDataInfo <List<NursingProject>> list(
            @ApiParam(value = "护理项目查询条件对象，可包含名称、单位、状态等过滤条件", required = false)
            NursingProject nursingProject) {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @ApiOperation(value = "导出护理项目数据", notes = "将符合条件的护理项目数据导出为 Excel 文件")
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(
            @ApiParam(value = "HTTP 响应对象，用于输出 Excel 文件流", required = true)
            HttpServletResponse response,
            @ApiParam(value = "导出时的筛选条件，与列表查询一致", required = false)
            NursingProject nursingProject) {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @ApiOperation(value = "根据ID获取护理项目详情", notes = "通过唯一ID获取单个护理项目的完整信息")
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping(value = "/{id}")
    public R<NursingProject> getInfo(
            @ApiParam(value = "护理项目唯一标识ID", required = true, example = "1")
            @PathVariable("id") Long id) {
        /*return success(nursingProjectService.selectNursingProjectById(id));*/
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @ApiOperation(value = "新增护理项目", notes = "创建一个新的护理项目记录，需提供必要字段信息")
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(
            @ApiParam(value = "护理项目新增数据对象，JSON 格式传入", required = true)
            @RequestBody NursingProject nursingProject) {
        nursingProjectService.insertNursingProject(nursingProject);
        return R.ok();
    }

    /**
     * 修改护理项目
     */
    @ApiOperation(value = "更新护理项目信息", notes = "根据ID更新已有护理项目的信息，字段为空则不更新对应项")
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(
            @ApiParam(value = "护理项目修改数据对象，必须包含有效的ID", required = true)
            @RequestBody NursingProject nursingProject) {
        nursingProjectService.updateNursingProject(nursingProject);
        return R.ok();
    }

    /**
     * 删除护理项目
     */
    @ApiOperation(value = "批量删除护理项目", notes = "根据一组ID逻辑或物理删除多个护理项目")
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(
            @ApiParam(value = "要删除的护理项目ID数组，支持批量删除", required = true, example = "[1,2,3]")
            @PathVariable Long[] ids) {
        nursingProjectService.deleteNursingProjectByIds(ids);
        return R.ok();
    }

    @ApiOperation(value = "获取所有护理项目列表")
    @GetMapping("/all")
    public R<List<NursingProjectVo>> listAll(){
        List<NursingProjectVo> list = nursingProjectService.listAll();
        return R.ok(list);


    }}
